const Router = require("koa-router");
const db = require("../../sql/mysql");
let router = new Router();

router.post("/api/list", async (ctx) => {
  console.log(ctx.request.body);
  let { pageNum = 1, pageSize = 10 } = ctx.request.body;
  let param = {
    pageNum: (pageNum - 1) * pageSize,
    pageSize: pageSize,
    initiator: "",
  };

  let result = await db.select("activity", "*", createSql(param));

  ctx.body = {
    result,
  };
});
function createSql(param) {
  let initSql = "";
  if (param.initiator != "") {
    initSql += `initiator like ${"%" + param.initiator + "%"} and `;
  }
  initSql += ` is_deleted=0 limit ${param.pageNum},${param.pageSize}`;
  return initSql;
}

module.exports = router;
